package com.da.javatest.leetCode;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author chenlida
 * @date 2019/1/8 14:48
 * @description
 */
public class Code677 {

}

class MapSum {

    /**
     * Initialize your data structure here.
     */
    private Map<String, Integer> result;

    public MapSum() {
        this.result = new HashMap<>();
    }

    public void insert(String key, int val) {
        result.put(key, val);
    }

    public int sum(String prefix) {
        return result.entrySet().stream().filter(e -> e.getKey().startsWith(prefix)).mapToInt(e -> e.getValue()).sum();
    }
}